
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title></title>
		<!-- 全局css引入 必须 -->
		<link href="<%=basePath%>/style/style.css" rel="stylesheet" type="text/css">
		<link href="<%=basePath%>/style/global.css" rel="stylesheet" type="text/css">
		<!--如用到ext必须引入 -->
		<jsp:include page="/ext-protoInclude.jsp" />
		<!-- 结束 -->
		<!-- 用到表单验证必须引入 -->
		<jsp:include page="/vailidateInclude.jsp" />
		<!-- 日期控件开始 -->
		<script type="text/javascript" src="<%=basePath%>/js/DatePicker/WdatePicker.js"></script>
		<!-- 日期控件结束 -->
		<!-- 部门选择js -->
		<script src="<%=basePath%>/js/selector/DeptSelector.js" type="text/javascript"></script>
		<script type="text/javascript" src='<%=basePath%>/dwr/interface/Tools.js'></script>
		<script type="text/javascript" src='<%=basePath%>/dwr/engine.js'></script>
		<script type="text/javascript" src='<%=basePath%>/dwr/util.js'></script>
	</head>
	<style>
.changedField {
	background-color: aqua;
	font-style: italic;
}
</style>
	<script type="text/javascript">
<!--
window.onload = function() {
    //Event.observe('infoForm', 'submit', submitMe);//监听infoForm的submit事件，当触发时调用submitMe
    Form.getElements('infoForm').each(//为表单每个field注册change事件
    	function(element) {
        	Event.observe($(element), 'blur', markChanged);
    	}
	);
}
//变动操作
function markChanged(event) {
	var obj=Event.element(event);
//如果有改变则加上changedField样式，否则移除changedField样式
	if(obj.defaultValue!=obj.value){
 		obj.addClassName('changedField');
	}else{
 		obj.removeClassName('changedField');
	}
}

//表单提交
function submitMe(event) {
    var changedElements = $$('.changedField');
    var faildElements=$$('.validation-failed');
    if(faildElements.length>0){
    	  alert("请检查数据是否正确！");
    	  return;
    }
    if (changedElements.length > 0) {
        var parameters = {};
       parameters['op'] = 'ajax';
       parameters['map.id'] = $('map.id').value;
       parameters['map.ygxm'] = $('map.ygxm').value;
        changedElements.each(
        	function(element) {
            	parameters[element.name] = element.value;
            	parameters[element.name+"_old"] = element.defaultValue;
            	element.removeClassName('changedField');
        	}
     	);
      Ext.Ajax.request({
                            url : 'saveUser.do',
                            method : 'POST',
                            params : parameters,
                            success : function(response, options) {
                                var res = Ext.util.JSON
                                        .decode(response.responseText);
                                if (res.success) {
                                    Ext.Msg.alert('操作信息', '保存成功！');
                                    window.location.reload();
                                } else {
                                    Ext.Msg.alert('操作信息', '保存失败！');
                                }
                            },
                            failure : function(response, options) {
                                Ext.Msg.alert('操作信息', '保存失败！');
                            },
                            scope : this
                        });	
	}
}

function extCallBack(id,text){
document.getElementById("deptid").value=id;
document.getElementById("deptname").value=text;
document.getElementById("deptname").focus();
document.getElementById("deptid").focus();
document.getElementById("dept.id").value=id;
}
function selShi(id,shiId,quId){
		DWREngine.setAsync(true); 
				if(id!=''){
				var sql="select code,value from dic where pcode='SHI' and min='"+id+"' order by code asc";
					Tools.getMapForSelect(sql,function(data){
						dwr.util.removeAllOptions(shiId);
						dwr.util.removeAllOptions(quId);
						var objshi=document.getElementById(shiId);
						var objqu=document.getElementById(quId);
						objshi.options[objshi.length] = new Option("请选择市", "");
						objqu.options[objqu.length] = new Option("请选择区", "");
    					dwr.util.addOptions(shiId, data);
					});
				}
}
function selQu(id,quId){
		DWREngine.setAsync(true); 
				if(id!=''){
				var sql="select code,value from dic where pcode='QU' and min='"+id+"' order by code asc";
					Tools.getMapForSelect(sql,function(data){
						dwr.util.removeAllOptions(quId);
    					dwr.util.addOptions(quId, data);
					});
				}
}
Ext.onReady(function(){
    <s:if test="map.size==0">
    	if(""=="${dept.id}" || "34000000"=="${dept.id}" ){
    		document.getElementById("deptname").value='${userinfor.bmmc}';
        	document.getElementById("deptid").value='${userinfor.id}';
    	}else{
    		document.getElementById("deptname").value='${dept.bmmc}';
        	document.getElementById("deptid").value='${dept.id}';
    	}
    </s:if>
});
//-->
</script>
	<body>
		<div class="rightCon">
			<div class="rightTitle2">
				<h3>
					<s:property value="nav" escape="false" />
				</h3>
			</div>
			<s:form action="saveUser.do" method="post" id="infoForm" cssClass="required-validate">
				<table class="formTable">
					<colgroup>
						<col class="formLabel" align="left" width="25%">
						<col align="left" />
						<col class="formLabel" align="left" />
						<col align="left" />
					</colgroup>
					<tr>
						<td>
							所属部门：
						</td>
						<td colspan="3">
							<s:hidden name="dept.id" id="dept.id" />
							<s:textfield cssStyle="width:0px;height:0px" name="map.bmid" id='deptid' />
							<s:textfield name="map.deptname" id='deptname' readonly="true" cssClass="required" size="40" />
							<span class="maintb1"> <input type="button" class="buttonSelect" value="选择" style="width: 50px; height: 20px;" onclick="DeptSelector.getView (extCallBack,true).show()" /> </span>
						</td>
					</tr>
					<tr>
						<td>
							员工编号：
							<s:hidden name="map.id" id="map.id" />
						</td>
						<td>
							<s:textfield name="map.ygzh" id="" cssClass="required"></s:textfield>
						</td>
						<td>
							员工姓名：
							<!-- ygxm -->
						</td>
						<td>
							<s:textfield name="map.ygxm" cssClass="required" id="map.ygxm"></s:textfield>
						</td>
					</tr>
					<tr>
						<td>
							职务：
							<!-- zhiwu -->
						</td>
						<td>
							<s:textfield name="map.ygzw"></s:textfield>
						</td>
						<td>
							排序：
							<!-- ygpx -->
						</td>
						<td>
							<s:textfield name="map.paixu" id="paixu" cssClass="validate-integer"></s:textfield>
						</td>
					</tr>
					<tr>
						<td>
							身份证：
						</td>
						<td colspan=3>
							<s:textfield name="map.sfz" cssStyle="width:200px;" id="" cssClass="validate-id-number"></s:textfield>
						</td>
					</tr>
					<tr>
						<td>
							固定电话：
							<!-- gddh -->
						</td>
						<td>
							<s:textfield name="map.tel" id="" cssClass="validate-phone"></s:textfield>
						</td>
						<td>
							手机号码：
							<!-- sjhm -->
						</td>
						<td>
							<s:textfield name="map.mobile" id="" cssClass="validate-mobile-phone"></s:textfield>
						</td>
					</tr>
					<tr>
						<td>
							备注：
						</td>
						<td colspan=3>
							<s:textfield name="map.bz1" id="" size="60"></s:textfield>
						</td>
					</tr>
				</table>
				<table class="form_submit_bar">
					<tr>
						<td width="30%" align="center" colspan="4">
							<s:if test="%{map.id==null}">
								<input class="buttonOk" id="button2" type="submit" value="保存" />
							&nbsp;&nbsp;&nbsp;&nbsp;</s:if>
							<s:else>
								<input class="buttonOk" id="button2" type="button" onclick="submitMe()" value="保存" />
							&nbsp;&nbsp;&nbsp;&nbsp; </s:else>
							<input class="buttonOk" id="button2" type="reset" value="重置" />
						</td>
					</tr>
				</table>
			</s:form>
	</body>
</html>